package com.honghu.villagepost.activity

import android.content.Context
import android.content.Intent
import androidx.recyclerview.widget.RecyclerView
import com.honghu.villagepost.adapter.OrderLogisticsAdapter
import com.honghu.villagepost.api.ApiService
import com.honghu.villagepost.base.BaseListActivity
import com.honghu.villagepost.callback.DialogCallback
import com.honghu.villagepost.callback.LzyResponse
import com.honghu.villagepost.entity.Logistics
import com.lzy.okgo.model.Response

/**
 * @author: mqwang
 * @create: 2/24/21 4:00 PM
 * @Description: 我的订单 - 寄件
 */
class LogisticsOrderActivity : BaseListActivity<Logistics>() {

    val orderLogisticsAdapter : OrderLogisticsAdapter by lazy {
        OrderLogisticsAdapter()
    }

    companion object{
        fun self(context: Context){
            val intent = Intent(context, LogisticsOrderActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun bindRecyclerView(recLv: RecyclerView) {
        setMainTitle("我的订单")
        recLv.adapter = orderLogisticsAdapter

        orderLogisticsAdapter.setOnItemClickListener { adapter, view, position ->
           var item = orderLogisticsAdapter.getItem(position) as Logistics
            LogisticsOrderDetailsActivity.self(mContext, item!!.logisticsNo)

        }

    }

    override fun loadData(page: Int, pageCount: Int) {
        ApiService.logistics_order(this, page, object : DialogCallback<LzyResponse<Logistics>>(){
            override fun onSuccess(response: Response<LzyResponse<Logistics>>?) {
                onGetDataSuc(response!!.body().data.records)
            }
        })
    }

    override fun getData(): MutableList<Logistics> {
        return orderLogisticsAdapter.data
    }

    override fun bindData(isRefresh: Boolean, list: MutableList<Logistics>?) {
        if (isRefresh)
            orderLogisticsAdapter.setNewData(list)
        else
            orderLogisticsAdapter.addData(list!!)
    }

}